import { resolve } from 'path';
import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'

const pathResolve = (dir) => {
  return resolve(__dirname, '.', dir);
};

export default defineConfig({
  transpileDependencies:['@dcloudio/uni-ui', 'uview-plus'],
  plugins: [
    uni(),
  ],
  // Vue编译器配置 - 修复uni-transition组件解析问题
  vue: {
    template: {
      compilerOptions: {
        isCustomElement: (tag) => {
          // 声明uni-app内置组件为自定义元素，避免Vue编译器报错
          return tag.startsWith('uni-') || tag.startsWith('u-') || tag.startsWith('up-')
        }
      }
    }
  },
  root: process.cwd(),
  resolve: {
    alias: [
      // 绝对路径重命名：/@/xxxx => src/xxxx
      {
        find: /\/@\//,
        replacement: pathResolve('src') + '/',
      },
      {
        find: /^~/,
        replacement: '',
      },
    ],
  },
  // 发布时删除console
  build: {
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: true,
      },
    },
  },
  // 开发服务器配置
  server: {
    port: 8080,
    host: '0.0.0.0',
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:8000',
        changeOrigin: true,
        ws: true
      }
    }
  }
}) 